package com.liruo.treasureattic.common.util.tree;

import com.liruo.treasureattic.common.util.tree.ci.Container;
import lombok.Getter;
import lombok.ToString;

import java.io.Serial;
import java.util.LinkedList;
import java.util.List;

/**
 * @Author:liruo
 * @Date:2022-12-13-19:59:04
 * @Desc
 */
@ToString
@Getter
public class UrlFolderAndUrlAssembleVo extends UrlFolderVo implements Container<Long>{
    @Serial
    private static final long serialVersionUID = -5658004569853352094L;
    private final List<UrlVo> urlVos = new LinkedList<>();
    private final List<UrlFolderAndUrlAssembleVo> subFolders = new LinkedList<>();
    @Override
    public Long obtainFFSA() {
        return getId();
    }
    @Override
    public Long obtainSFSA() {
        return getFid();
    }
    @Override
    public boolean isSubItem(Object item) {
        return item instanceof  UrlVo && getId() != null && getId().equals(((UrlVo)item).getFid());
    }
    @Override
    public void addItem(Object item) {
        urlVos.add((UrlVo)item);
    }

    @Override
    public boolean isSubContainer(Container<Long> subContainer) {
        return obtainFFSA() != null && obtainFFSA().equals(subContainer.obtainSFSA());
    }

    @Override
    public void addSubFContainer(Container<Long> subContainer) {
//        if(!(subContainer instanceof UrlFolderAndUrlAssembleVo)){
//            throw new ErrContainerException("need %s, but provide %s"
//                    .formatted(
//                            UrlFolderAndUrlAssembleVo.class.getName(),
//                            subContainer.getClass().getName()
//                    )
//            );
//        }
        subFolders.add((UrlFolderAndUrlAssembleVo)subContainer);
    }

    @Override
    public List<? extends Container<Long>> obtainSubContainers() {
        return this.subFolders;
    }


//    @Serial
//    private static final long serialVersionUID = TreasureAtticConstant.TREASURE_ATTIC_VERSION;
}
